<template>
<h1>循环指令</h1>

  <ul>
<!--    item从1开始，没执行一次，item的值加一，一直到n  -->
<!-- v-for:执行六次，生成六个li   -->
    <li v-for="item in 6">{{item}}</li>
  </ul>

  <ul>
    <li v-for="item in proArr">{{item}}</li>
  </ul>

  <table border="1px">
    <tr>
      <th>汽车编号</th>
      <th>商品名称</th>
      <th>商品价格</th>
      <th>商品库存</th>
      <th>操作</th>
    </tr>
    <tr v-for="(item,index) in proArr">
      <td>{{index+1}}</td>
      <td>{{item.title}}</td>
      <td>{{item.price}}</td>
      <td>{{item.num}}</td>
      <td> <button @click="del(index)">删除</button></td>
    </tr>
  </table>
</template>

<script setup>
import {ref} from "vue";

const proArr = ref([
    {title:'奔驰',price:'20',num:'200'},
    {title:'宝马',price:'30',num:'300'},
    {title:'宾利',price:'40',num:'400'},
    {title:'su7',price:'50',num:'500'}])

const del = (i)=>{
  if(confirm('确定删除吗？')){
    // 从下标i开始删除一个元素
    proArr.value.splice(i,1);
  }
}
</script>


<style scoped>

</style>